package com.tiancheng.onecode.trade.configuration;

import com.tiancheng.onecode.trade.TradeApiClient;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * @Author: kellen
 * @Description: 交易api自动配置
 * @Date: create in 2024/12/9 16:32
 */
@Configuration
@EnableConfigurationProperties(TradeApplicationProperties.class)
@AutoConfigureAfter({TradeApplicationProperties.class})
@ConditionalOnProperty(prefix = "trade", value = {"hosts", "client-id"})
public class TradeApiAutoConfiguration {

    /**
     * 服务请求bean
     */
    @Bean
    @ConditionalOnMissingBean
    @DependsOn("springContextHolder")
    public TradeApiClient platformRequest(TradeApplicationProperties applicationProperties) {
        return new TradeApiClient(applicationProperties);
    }

}
